import { $planet_DataManager_poof$ } from "../../../frame/ALIB/lib.data";
import { $planet_PLANET_ID_LIST_poof$, $planet_TARGET_PLANET_LIST_poof$ } from "../../config.global";
import $planet_get_proxy_status_poof$ from "../../src/data/data.status";
import $planet_get_proxy_trigger_poof$ from "../../src/data/data.trigger";
import $planet_get_proxy_user_poof$ from "../../src/data/data.user";

export default class $planet_GameDC_poof$ {
	private static $planet___trigger___poof$: ReturnType<typeof $planet_get_proxy_trigger_poof$>;
	private static $planet___user___poof$: ReturnType<typeof $planet_get_proxy_user_poof$>;
	private static $planet___status___poof$: ReturnType<typeof $planet_get_proxy_status_poof$>;

	public static get $planet_trigger_poof$(){
		return $planet_GameDC_poof$.$planet___trigger___poof$;
	}
	public static get $planet_user_poof$(){
		return $planet_GameDC_poof$.$planet___user___poof$;
	}
	public static get $planet_status_poof$(){
		return $planet_GameDC_poof$.$planet___status___poof$;
	}

	public static get $planet_target_planet_poof$(){
		return $planet_GameDC_poof$.$planet___user___poof$.$planet_target_planet_poof$ as typeof $planet_PLANET_ID_LIST_poof$[number];
	}

	public static $planet_init_poof$(){
		$planet_GameDC_poof$.$planet___trigger___poof$ = $planet_get_proxy_trigger_poof$('$planet_game_trigger_poof$');
		$planet_GameDC_poof$.$planet___user___poof$ = $planet_get_proxy_user_poof$('$planet_game_user_poof$');
		$planet_GameDC_poof$.$planet___status___poof$ = $planet_get_proxy_status_poof$('$planet_game_status_poof$');

		while($planet_GameDC_poof$.$planet_follow_cache_poof$.length>0){
			let [pxi_uri, key, call, update, np] = $planet_GameDC_poof$.$planet_follow_cache_poof$.pop();
			//@ts-ignore
			$planet_GameDC_poof$.$planet_follow_poof$(pxi_uri, key, call, update).then(reg=>np.$planet_resolve_poof$(reg));
		}
	}

	private static $planet_follow_cache_poof$: [string, string, Function, boolean, abd.$planet_NudityPromise_poof$<ReturnType<typeof $planet_DataManager_poof$.$planet_follow_poof$>>][] = [];
    /**
     * 注册监听
     * @param data 要监听的数据
     * @param key 要监听的字段
     * @param call 更新时触发的回调函数
     * @param update 是否在注册时触发回调
     */
	public static $planet_follow_poof$<P extends Exclude<abd.$planet_OmitKeys_poof$<typeof $planet_GameDC_poof$, Function>, 'prototype'>, D extends typeof $planet_GameDC_poof$[P], K extends abd.$planet_OmitKeys_poof$<D, Function>>(pxi_uri: P, key: K, call: (o: D[K], v: D[K])=>void, update?: boolean){
		let pxi = Reflect.get($planet_GameDC_poof$, pxi_uri);
		let np = new abd.$planet_NudityPromise_poof$<ReturnType<typeof $planet_DataManager_poof$.$planet_follow_poof$>>();
		update = update??true;
		if(!pxi){
			//@ts-ignore
			$planet_GameDC_poof$.$planet_follow_cache_poof$.unshift([pxi_uri, key, call, update, np]);
		}else{
			//@ts-ignore
			np.$planet_resolve_poof$($planet_DataManager_poof$.$planet_follow_poof$(pxi, key, call, update));
		}

		return np.$planet_promise_poof$;
	}

	/** 刷新下一个目标球 */
	public static $planet_nextTargetPlanet_poof$(){
		let index = Math.min($planet_TARGET_PLANET_LIST_poof$.length-1, $planet_TARGET_PLANET_LIST_poof$.indexOf($planet_GameDC_poof$.$planet_target_planet_poof$)+1);
		$planet_GameDC_poof$.$planet_user_poof$.$planet_target_planet_poof$ = $planet_TARGET_PLANET_LIST_poof$[index];
		return $planet_GameDC_poof$.$planet_target_planet_poof$;
	}
}